home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-13 / thesrc10.zip / SHOW.C < prev    next >
C/C++ Source or Header  |  1992-08-12  |  19KB  |  567 lines

  1. /***********************************************************************/
  2. /* SHOW.C - Functions involving displaying the data.                   */
  3. /***********************************************************************/
  4. /*
  5.  * THE - The Hessling Editor. A text editor similar to VM/CMS xedit.
  6.  * Copyright (C) 1991,1992 Mark Hessling
  7.  *
  8.  * This program is free software; you can redistribute it and/or
  9.  * modify it under the terms of the GNU General Public License as
  10.  * published by the Free Software Foundation; either version 2 of
  11.  * the License, or any later version.
  12.  *
  13.  * This program is distributed in the hope that it will be useful,
  14.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16.  * General Public License for more details.
  17.  *
  18.  * You should have received a copy of the GNU General Public License
  19.  * along with this program; if not, write to:
  20.  *
  21.  *    The Free Software Foundation, Inc.
  22.  *    675 Mass Ave,
  23.  *    Cambridge, MA 02139 USA.
  24.  *
  25.  *
  26.  * If you make modifications to this software that you feel increases
  27.  * it usefulness for the rest of the community, please email the
  28.  * changes, enhancements, bug fixes as well as any and all ideas to me.
  29.  * This software is going to be maintained and enhanced as deemed
  30.  * necessary by the community.
  31.  *
  32.  * Mark Hessling                     email: M.Hessling@itc.gu.edu.au
  33.  * 36 David Road                     Phone: +61 7 849 7731
  34.  * Holland Park                      Fax:   +61 7 875 7877
  35.  * QLD 4121
  36.  * Australia
  37.  */
  38. #include <stdio.h>
  39. #include <stdlib.h>
  40. #include <time.h>
  41.  
  42. #include "the.h"
  43.  
  44. /*#define TRACEE*/
  45. /*-------------------------- external data ----------------------------*/
  46. extern LINE *next_line,*curr_line;
  47. extern VIEW_DETAILS *vd_current,*vd_first,*vd_mark;
  48. extern char current_screen;
  49. extern SCREEN_DETAILS screen[MAX_SCREENS];        /* screen structures */
  50. extern char current_file;         /* pointer to current file */
  51. extern char number_of_views;                        /* number of views */
  52. extern char number_of_files;                   /* number of open files */
  53. extern char display_screens;                      /* number of screens */
  54. extern bool horizontal;
  55. extern WINDOW *foot,*error_window;
  56. extern char error_on_screen;
  57. extern unsigned char *rec;
  58. extern unsigned short rec_len;
  59. extern unsigned char *cmd_rec;
  60. extern unsigned short cmd_rec_len;
  61. extern unsigned char mode_insert;        /* defines insert mode toggle */
  62. extern unsigned char in_profile;    /* indicates if processing profile */
  63. extern char file_disposition;
  64. /*-------------------------- function definitions ---------------------*/
  65. #ifdef PROTO
  66. static LINE *show_line(unsigned short,LINE *,short,short);
  67. void show_one_row(unsigned char *,unsigned short,unsigned short,LINE *);
  68. void highlight_line(unsigned char,long);
  69. void show_highlighted_lines(void);
  70. #else
  71. static LINE *show_line();
  72. void show_one_row();
  73. void highlight_line();
  74. void show_highlighted_lines();
  75. #endif
  76. /***********************************************************************/
  77. #ifdef PROTO
  78. void show_heading(int key)
  79. #else
  80. void show_heading(key)
  81. int key;
  82. #endif
  83. /***********************************************************************/
  84. {
  85. /*--------------------------- local data ------------------------------*/
  86.  short y,x,fpath_len,fname_len,max_name;
  87.  char buffer[60];
  88.  register int i;
  89. /*--------------------------- processing ------------------------------*/
  90. #ifdef TRACE
  91.  trace_function("show.c:    show_heading");
  92. #endif
  93.  for (i=0;i<CURRENT_SCREEN.screen_cols-1;i++)
  94.      mvwaddch(CURRENT_WINDOW_IDLINE,0,i,' ');
  95.  getyx(CURRENT_WINDOW,y,x);
  96.  if (CURRENT_VIEW->current_window == WINDOW_COMMAND)
  97.     y = (short)CURRENT_VIEW->current_line;
  98.  else
  99.     y = (short)CURRENT_VIEW->focus_line;
  100.  if (display_screens != 1 && !horizontal)
  101.    {
  102.     sprintf(buffer,"L=%-.1d C=%-.1d S=%-.1d A=%d,%d",
  103.                     y,x+1+CURRENT_VIEW->verify_col-1,
  104.                     CURRENT_FILE->number_lines,
  105.                     CURRENT_FILE->autosave_alt,
  106.                     CURRENT_FILE->save_alt);
  107.     max_name = (CURRENT_SCREEN.screen_cols-1) - strlen(buffer);
  108.    }
  109.  else
  110.     max_name = (CURRENT_SCREEN.screen_cols-48);
  111.  fpath_len = strlen(CURRENT_FILE->fpath);
  112.  fname_len = strlen(CURRENT_FILE->fname);
  113.  if (fpath_len + fname_len > max_name)
  114.    {
  115.     fpath_len = (fpath_len + fname_len + 3) - max_name;
  116.     wmove(CURRENT_WINDOW_IDLINE,0,0);
  117.     wprintw(CURRENT_WINDOW_IDLINE,"...%s%s",(CURRENT_FILE->fpath+fpath_len),CURRENT_FILE->fname);
  118.    }
  119.  else
  120.   {
  121.    wmove(CURRENT_WINDOW_IDLINE,0,0);
  122.    wprintw(CURRENT_WINDOW_IDLINE,"%s%s",CURRENT_FILE->fpath,CURRENT_FILE->fname);
  123.   }
  124.  if (display_screens != 1 && !horizontal)
  125.    {
  126.     wmove(CURRENT_WINDOW_IDLINE,0,max_name+1);
  127.     wprintw(CURRENT_WINDOW_IDLINE,"%-s",buffer);
  128.    }
  129.  else
  130.    {
  131.     wmove(CURRENT_WINDOW_IDLINE,0,34);
  132.     wprintw(CURRENT_WINDOW_IDLINE,"Line=%-6.1d Col=%-5.1d",y,x+1+CURRENT_VIEW->verify_col-1);
  133.     wmove(CURRENT_WINDOW_IDLINE,0,54);
  134.     wprintw(CURRENT_WINDOW_IDLINE,"Size=%-6.1d",CURRENT_FILE->number_lines);
  135.     wmove(CURRENT_WINDOW_IDLINE,0,66);
  136.     wprintw(CURRENT_WINDOW_IDLINE,"Alt=          ");
  137.     wmove(CURRENT_WINDOW_IDLINE,0,70);
  138.     wprintw(CURRENT_WINDOW_IDLINE,"%d,%d",CURRENT_FILE->autosave_alt,
  139.                              CURRENT_FILE->save_alt);
  140.    }
  141.  wnoutrefresh(CURRENT_WINDOW_IDLINE);
  142. #ifdef TRACE
  143.  trace_return();
  144. #endif
  145.  return;
  146. }
  147. /***********************************************************************/
  148. #ifdef PROTO
  149. void show_footing(void)
  150. #else
  151. void show_footing()
  152. #endif
  153. /***********************************************************************/
  154. {
  155. /*--------------------------- local data ------------------------------*/
  156.  short y,x;
  157. int key;
  158. WINDOW *w;
  159. time_t timer;
  160. struct tm *tblock;
  161. /*--------------------------- processing ------------------------------*/
  162. #ifdef TRACE
  163.  trace_function("show.c:    show_footing");
  164. #endif
  165.  w = CURRENT_WINDOW;
  166.  
  167.  if (CURRENT_VIEW->current_window == WINDOW_MAIN)
  168.    {
  169.     getyx(CURRENT_WINDOW,y,x);
  170.     key = *(rec+CURRENT_VIEW->verify_col-1+x);
  171.    }
  172.  else
  173.     key = (int)(winch(w) & A_CHARTEXT);
  174.  
  175.  wmove(foot,0,62);
  176.  if (key == '\0')
  177.     wprintw(foot,"' '=00/000 ");
  178.  else
  179.     wprintw(foot,"'%1.1c'=%2.2X/%3.3d ",key,key,key);
  180.  
  181.  wmove(foot,0,76);
  182.  if (mode_insert)
  183.     wprintw(foot,"Ins");
  184.  else
  185.     wprintw(foot,"   ");
  186.  
  187.  wmove(foot,0,74);
  188. #ifdef COLOR_CURSES
  189.  if (has_colors() == TRUE)
  190.     wprintw(foot,"C");
  191.  else
  192.     wprintw(foot,"m");
  193. #else
  194.  wprintw(foot,"M");
  195. #endif
  196.  
  197.  wmove(foot,0,11);
  198.  wprintw(foot,"Files=%d ",number_of_files);
  199. /*#define TRACEE*/
  200. #ifdef TRACEE
  201.  wmove(foot,0,20);
  202.  wprintw(foot,"            ");
  203.  wmove(foot,0,20);
  204.  wprintw(foot,"C<%ld>F<%ld>",CURRENT_VIEW->current_line,CURRENT_VIEW->focus_line);
  205. #endif
  206. /*---------------------------------------------------------------------*/
  207. /* Get the current time, and display it.                               */
  208. /*---------------------------------------------------------------------*/
  209.  timer = time(NULL);
  210.  tblock = localtime(&timer);
  211.  wmove(foot,0,54);
  212.  
  213.  wprintw(foot,"%2d:%02.2d%s",
  214.         (tblock->tm_hour > 12) ? (tblock->tm_hour-12) : (tblock->tm_hour),
  215.          tblock->tm_min,
  216.         (tblock->tm_hour >= 12) ? ("pm") : ("am"));
  217.  
  218.  wnoutrefresh(foot);
  219. #ifdef TRACE
  220.  trace_return();
  221. #endif
  222.  return;
  223. }
  224. /***********************************************************************/
  225. #ifdef PROTO
  226. void show_page(void)
  227. #else
  228. void show_page()
  229. #endif
  230. /***********************************************************************/
  231. {
  232. /*--------------------------- local data ------------------------------*/
  233.  register int i,row;
  234.  LINE *curr,*save_curr;
  235.  short cline,crow;
  236.  unsigned short x,y;
  237.  crow = CURRENT_VIEW->current_row;
  238.  cline = CURRENT_VIEW->current_line;
  239. /*--------------------------- processing ------------------------------*/
  240. #ifdef TRACE
  241.  trace_function("show.c:    show_page");
  242. #endif
  243.  if (in_profile)
  244.    {
  245. #ifdef TRACE
  246.     trace_return();
  247. #endif
  248.     return;
  249.    }
  250.  
  251.  save_curr = curr = ll_find(CURRENT_FILE->first_line,(long)cline);
  252.  getyx(CURRENT_WINDOW_MAIN,y,x);
  253. /*---------------------------------------------------------------------*/
  254. /* Display the file contents from the current line to the bottom of the*/
  255. /* window.                                                             */
  256. /*---------------------------------------------------------------------*/
  257.  for (i=0,row=crow;row<CURRENT_SCREEN.rows;row++,i++)
  258.       curr = show_line(YES,curr,row,i);
  259. /*---------------------------------------------------------------------*/
  260. /* Display the file contents from the current line to the top of the   */
  261. /* window.                                                             */
  262. /*---------------------------------------------------------------------*/
  263.  curr = save_curr->prev;
  264.  for (i=(-1),row=crow-1;row>-1;row--,i--)
  265.       curr = show_line(NO,curr,row,i);
  266.  
  267. /*---------------------------------------------------------------------*/
  268. /* Display any highlighted lines if there are any to display.          */
  269. /*---------------------------------------------------------------------*/
  270.  if (MARK_VIEW != (VIEW_DETAILS *)NULL)
  271.     show_highlighted_lines();
  272. /*---------------------------------------------------------------------*/
  273. /* Highlight the current line. If the current line is inside the marked*/
  274. /* block, use a different colour. If the current line is the top or    */
  275. /* bottom lines, use another colour again.                             */
  276. /*---------------------------------------------------------------------*/
  277.  if (MARK_VIEW == CURRENT_VIEW
  278.  &&  CURRENT_VIEW->current_line >= CURRENT_VIEW->mark_start_line
  279.  &&  CURRENT_VIEW->current_line <= CURRENT_VIEW->mark_end_line)
  280.      highlight_line(CURRENT_VIEW->current_row,colour[ATTR_CBLOCK]);
  281.  else
  282.      if (CURRENT_VIEW->current_line == 0L
  283.      ||  CURRENT_VIEW->current_line == CURRENT_FILE->number_lines + 1L)
  284.         highlight_line(CURRENT_VIEW->current_row,colour[ATTR_CTOFEOF]);
  285.      else
  286.         highlight_line(CURRENT_VIEW->current_row,colour[ATTR_CURLINE]);
  287.  
  288.  wrefresh(CURRENT_WINDOW_MAIN);
  289.  if (CURRENT_VIEW->prefix_on)
  290.      wrefresh(CURRENT_WINDOW_PREFIX);
  291.  
  292.  wmove(CURRENT_WINDOW_MAIN,y,x);
  293. #ifdef TRACE
  294.  trace_return();
  295. #endif
  296.  return;
  297. }
  298. /***********************************************************************/
  299. #ifdef PROTO
  300. static LINE *show_line(unsigned short going_down,LINE *curr_line,
  301.                          short row,short i)
  302. #else
  303. static LINE *show_line(going_down,curr_line,row,i)
  304. unsigned short going_down;
  305. LINE *curr_line;
  306. short row;
  307. short i;
  308. #endif
  309. /***********************************************************************/
  310. {
  311. /*--------------------------- local data ------------------------------*/
  312.  short cline,y;
  313.  LINE *curr;
  314. /*--------------------------- processing ------------------------------*/
  315. #ifdef TRACE
  316.  trace_function("show.c:    show_line");
  317. #endif
  318.  curr = curr_line;
  319.  cline = CURRENT_VIEW->current_line;
  320.  
  321.  if (curr == NULL)
  322.     {
  323.      wmove(CURRENT_WINDOW_MAIN,row,0);
  324.      wclrtoeol(CURRENT_WINDOW_MAIN);
  325.      if (CURRENT_VIEW->prefix_on) /* display prefix if on */
  326.        {
  327.         wmove(CURRENT_WINDOW_PREFIX,row,0);
  328.         wclrtoeol(CURRENT_WINDOW_PREFIX);
  329.        }
  330.     }
  331.  else
  332.     {
  333. /*---------------------------------------------------------------------*/
  334. /* Determine the row that is the focus line.                           */
  335. /*---------------------------------------------------------------------*/
  336.      y = get_row_for_focus_line(CURRENT_VIEW->current_row,
  337.                                CURRENT_VIEW->focus_line,
  338.                                CURRENT_VIEW->current_line);
  339. /*---------------------------------------------------------------------*/
  340. /* If the current row to be displayed is the focus line, display       */
  341. /* the working area, rec and rec_len instead of the entry in the LL.   */
  342. /*---------------------------------------------------------------------*/
  343.      if (row == y)
  344.         show_one_row(rec,rec_len,row,curr);
  345.      else
  346.         show_one_row(curr->line,curr->length,row,curr);
  347. /*---------------------------------------------------------------------*/
  348. /* If the prefix area is ON display it.                                */
  349. /*---------------------------------------------------------------------*/
  350.      if (CURRENT_VIEW->prefix_on)
  351.        {
  352.         wmove(CURRENT_WINDOW_PREFIX,row,0);
  353.         wprintw(CURRENT_WINDOW_PREFIX,"%6.6d",cline+i);
  354.        }
  355.      if (going_down)
  356.         curr = curr->next;
  357.      else
  358.         curr = curr->prev;
  359.     }
  360. #ifdef TRACE
  361.  trace_return();
  362. #endif
  363.  return(curr);
  364. }
  365. /***********************************************************************/
  366. #ifdef PROTO
  367. void show_one_row(unsigned char *line,unsigned short length,
  368.                   unsigned short row,LINE *curr)
  369. #else
  370. void show_one_row(line,length,row,curr)
  371. unsigned char *line;
  372. unsigned short length,row;
  373. LINE *curr;
  374. #endif
  375. /***********************************************************************/
  376. {
  377. /*--------------------------- local data ------------------------------*/
  378.  short col1,col2;
  379.  register int i;
  380. /*--------------------------- processing ------------------------------*/
  381. #ifdef TRACE
  382.  trace_function("show.c:    show_one_row");
  383. #endif
  384.  col1 = CURRENT_VIEW->verify_col - 1;
  385.  col2 = min(length-1,CURRENT_VIEW->verify_end-1);
  386. /*---------------------------------------------------------------------*/
  387. /* If we are displaying the top or bottom line marker, then force the  */
  388. /* function to display the beginning of the line and to display the    */
  389. /* whole line when VERIFY is in effect.                                */
  390. /*---------------------------------------------------------------------*/
  391.  if (curr->prev == NULL || curr->next == NULL)
  392.    {
  393.     col1 = 0;
  394.     col2 = curr->length-1;
  395.     wattrset(CURRENT_WINDOW_MAIN,colour[ATTR_TOFEOF]);
  396.    }
  397. /*---------------------------------------------------------------------*/
  398. /* If the first column to be displayed is after the length of the line */
  399. /* then just clear to end of line and exit.                            */
  400. /*---------------------------------------------------------------------*/
  401.  if (col1 >= length)
  402.    {
  403.      wmove(CURRENT_WINDOW_MAIN,row,0);
  404.      wclrtoeol(CURRENT_WINDOW_MAIN);
  405.      wattrset(CURRENT_WINDOW_MAIN,colour[ATTR_FILEAREA]);
  406. #ifdef TRACE
  407.      trace_return();
  408. #endif
  409.      return;
  410.    }
  411.  for (i=0;i<CURRENT_SCREEN.cols;i++)
  412.      {
  413.       if (i+col1 > col2)
  414.         {
  415.          wmove(CURRENT_WINDOW_MAIN,row,i);
  416.          wclrtoeol(CURRENT_WINDOW_MAIN);
  417.          break;
  418.         }
  419.       else
  420.         {
  421.          wmove(CURRENT_WINDOW_MAIN,row,i);
  422.          put_char(CURRENT_WINDOW_MAIN,*(line+i+col1),ADDCHAR);
  423.         }
  424.      }
  425.  wattrset(CURRENT_WINDOW_MAIN,colour[ATTR_FILEAREA]);
  426. #ifdef TRACE
  427.  trace_return();
  428. #endif
  429.  return;
  430. }
  431. /***********************************************************************/
  432. #ifdef PROTO
  433. void highlight_line(unsigned char line,long attrib)
  434. #else
  435. void highlight_line(line,attrib)
  436. unsigned char line;
  437. long attrib;
  438. #endif
  439. /***********************************************************************/
  440. {
  441. /*--------------------------- local data ------------------------------*/
  442.  register int i;
  443.  unsigned char ch;
  444.  WINDOW *w;
  445. /*--------------------------- processing ------------------------------*/
  446. #ifdef TRACE
  447.  trace_function("show.c:    highlight_line");
  448. #endif
  449.  wmove(CURRENT_WINDOW_MAIN,line,0);
  450.  wattrset(CURRENT_WINDOW_MAIN,attrib);
  451.  for (i=0;i<CURRENT_SCREEN.cols;i++)
  452.     {
  453.      w = CURRENT_WINDOW_MAIN;
  454.      ch = (unsigned char)winch(w) & A_CHARTEXT;
  455.      wmove(CURRENT_WINDOW_MAIN,line,i);
  456.      put_char(CURRENT_WINDOW_MAIN,ch,ADDCHAR);
  457.     }
  458.  wattrset(CURRENT_WINDOW_MAIN,colour[ATTR_FILEAREA]);
  459. /* touchline(CURRENT_WINDOW_MAIN,line,1);*/
  460. #ifdef TRACE
  461.  trace_return();
  462. #endif
  463.  return;
  464. }
  465. /***********************************************************************/
  466. #ifdef PROTO
  467. void show_highlighted_lines(void)
  468. #else
  469. void show_highlighted_lines()
  470. #endif
  471. /***********************************************************************/
  472. {
  473. /*--------------------------- local data ------------------------------*/
  474.  register int i;
  475.  short num_rows,top_row;
  476.  long top_line,bottom_line;
  477. /*--------------------------- processing ------------------------------*/
  478. #ifdef TRACE
  479.  trace_function("show.c:    show_highlighted_lines");
  480. #endif
  481.  top_line = max(CURRENT_VIEW->mark_start_line,
  482.                 CURRENT_VIEW->current_line-(long)CURRENT_VIEW->current_row);
  483.  bottom_line = min(CURRENT_VIEW->mark_end_line,
  484.                    CURRENT_VIEW->current_line-(long)CURRENT_VIEW->current_row+(long)CURRENT_SCREEN.rows);
  485.  top_row = get_row_for_focus_line(CURRENT_VIEW->current_row,
  486.                                   top_line,
  487.                                   CURRENT_VIEW->current_line);
  488.  num_rows = (short)(bottom_line - top_line + 1);
  489.  for (i=0;i<num_rows;i++)
  490.     if (MARK_VIEW == CURRENT_VIEW)
  491.        highlight_line((unsigned char)(i+top_row),colour[ATTR_BLOCK]);
  492.     else
  493.        highlight_line((unsigned char)(i+top_row),colour[ATTR_FILEAREA]);
  494.  if (MARK_VIEW != CURRENT_VIEW)
  495.    {
  496.     CURRENT_VIEW->mark_start_line = CURRENT_VIEW->mark_end_line = (-1L);
  497.     touchline(CURRENT_WINDOW_MAIN,top_row,num_rows);
  498.    }
  499. #ifdef TRACE
  500.  trace_return();
  501. #endif
  502.  return;
  503. }
  504. /***********************************************************************/
  505. #ifdef PROTO
  506. void redraw_window(WINDOW *win)
  507. #else
  508. void redraw_window(win)
  509. WINDOW *win;
  510. #endif
  511. /***********************************************************************/
  512. {
  513. /*--------------------------- local data ------------------------------*/
  514.  register int i,j;
  515.  int key;
  516.  short y,x;
  517. /*--------------------------- processing ------------------------------*/
  518. #ifdef TRACE
  519.  trace_function("show.c:    redraw_window");
  520. #endif
  521.  getyx(win,y,x);
  522.  for (i=0;i<getmaxx(win);i++)
  523.      for (j=0;j<getmaxy(win);j++)
  524.         {
  525.          wmove(win,j,i);
  526.          key = (int)(winch(win) & A_CHARTEXT);
  527.          waddch(win,key);
  528.         }
  529.  wmove(win,y,x);
  530. #ifdef TRACE
  531.  trace_return();
  532. #endif
  533.  return;
  534. }
  535. /***********************************************************************/
  536. #ifdef PROTO
  537. void repaint_screen(void)
  538. #else
  539. void repaint_screen()
  540. #endif
  541. /***********************************************************************/
  542. {
  543. /*--------------------------- local data ------------------------------*/
  544.  short y,x;
  545. /*--------------------------- processing ------------------------------*/
  546. #ifdef TRACE
  547.  trace_function("show.c:    repaint_screen");
  548. #endif
  549.  
  550.  getyx(CURRENT_WINDOW,y,x);
  551.  y = get_row_for_focus_line(CURRENT_VIEW->current_row,
  552.                             CURRENT_VIEW->focus_line,
  553.                             CURRENT_VIEW->current_line);
  554.  if (x > CURRENT_SCREEN.cols)
  555.     x = 0;
  556.  pre_process_line(CURRENT_VIEW->focus_line);
  557.  show_page();
  558.  cleanup_command_line();
  559.  show_heading((int)0);
  560.  wmove(CURRENT_WINDOW,y,x);
  561.  
  562. #ifdef TRACE
  563.  trace_return();
  564. #endif
  565.  return;
  566. }
  567.